#ifndef RTE_OS_RTOS_H
#define RTE_OS_RTOS_H


#ifdef windows_x86
#define PriorityNormal 0
#define PriorityRealtime 1
#endif
#ifdef LINUX
#define PriorityNormal 0
#define PriorityRealtime 1
#endif
#ifdef SYLIXOS

#include <SylixOS.h>
#include <pthread.h>

#define PriorityNormal LW_PRIO_NORMAL
#define PriorityRealtime LW_PRIO_REALTIME
#endif

#ifdef USE_FREERTOS

#include "STM32FreeRTOS.h"

#define PriorityLow osPriorityLow
#define PriorityNormal osPriorityNormal
#define PriorityRealtime osPriorityRealtime
#endif
#ifdef USE_CODEBRICK
#define PriorityNormal 0
#define PriorityRealtime 1
#endif
#ifdef USE_STASK

#include "s_task.h"

#define PriorityNormal 0
#define PriorityRealtime 1
#endif

typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef int s32;
using u64 = unsigned long long;
using uint8_t = unsigned char;
using uint16_t = unsigned short;

/*
 * @brief 操作系统接口封装
 */
class rtos {
public:
    /*
     * @brief 启动
     */
    void begin();

    /*
     * @brief 线程操作
     */
    static void *
    create_thread_run(const char *name, u32 stack_size, int poriority, void *func, const void *arg);

    static void thread_close(void *);

    static u32 pthread_self();

    static void sched_yield();

    /*
     * @brief 时间操作
     */
    static void Delay(u32 ms);

    /*
     * @brief 运行毫秒数，
     * @todo:49天左右会复位一次
     */
    static u32 ticks();

    /*
     * @brief  70以来微秒数，
     */
    static u64 current_us();

    /*
     * @brief 70以来秒数
     */
    static u32 timestamp();

    /*
     * @brief 信号量
     */
    static void *Create_Mutex();

    static int mutex_lock(const void *, int = -1);

    static bool mutex_trylock(const void *pVoid);

    static int mutex_unlock(const void *);

    static void mutex_destroy(const void *pVoid);

    //@ 剩余内存
    static u16 mem_remain();

    /*
     * @brief CPU使用率
     */
    static u16 OSCPUUsage();


};

#endif // RTE_OS_RTOS_H
